/****************************************************************************\
* PROJECT: xmega-music-player												 *
* Created By: Alex Arseneau													 *
* File: state_machine.h														 *
*																			 *
* Desc: contains typedefs, data structures and other prototypes specifically *
* used to create and run the system state machine							 *
 ****************************************************************************/
#ifndef STATE_MACHINE_H
#define STATE_MACHINE_H

#include <stdint.h>

extern "C"
{
	#include "fat32.h"
};

// Primary System Steps (Used to make code easier to read by subdiving step into logical groups and therefore separate dostep() functions)
typedef enum current_system_sequence_e {
	IDLE = 0,
	MEDIA_INSERTED,
	MEDIA_REMOVED,
	DECODING_MP3,
} current_system_sequence_t;

// Enumeration of all possible states (used to construct sequences)
typedef enum system_step_e {
	START_STEP = 0,
	END_STEP,

	BEGIN_SD_INIT,
	SETUP_SD_CARD,
	SETUP_FAT_LIB,
	SETUP_DECODER,

	CANCEL_PLAYBACK,
	DISABLE_FAT_LIB,
	DISABLE_MUSIC_LIB,

	FIND_FIRST_FILE,
	START_PLAYBACK,
	CONTINUE_PLAYBACK,
	SONG_FINISHED,
	PLAYBACK_FINISH,
	GET_NEXT_FILE,
	GET_PREV_FILE,

	SKIP_SONG,
	PREV_SONG,

	PAUSE_PLAYBACK,
	PAUSED,
	RESUME_PLAYBACK,

	LAST_STEP

} system_step_t;

typedef enum sd_state_s
{
	NO_MEDIA,
	MEDIA_CONNECTED
} sd_state_t;

typedef struct SystemStatus_s
{
	current_system_sequence_t state; // The state we are currently in

	system_step_t * sequence; // Array of steps

	uint8_t step;

	uint8_t sequence_complete;

	volatile uint8_t media_changed;
	volatile sd_state_t media_state;

	volatile uint8_t button_to_handle;
	volatile uint8_t button_pressed;

	bool increment; // Used to determine the step in the seq should be increased

	volatile uint8_t volume;

	volatile uint8_t update_volume;

	 FAT_FILE_t * fp;

	uint8_t buf[512];

} SystemStatus_t;



#endif /* STATE_MACHINE_H */